﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TagRepositoryTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Tests.TagRepositoryTests" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Tests
{
    using System;
    using System.Linq;
    using Common;
    using Interfaces;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Tests.TagRepositoryTests"/> type.
    /// </summary>
    [TestClass]
    public class TagRepositoryTests
    {
        /// <summary>
        /// Mock repository for testing translation
        /// </summary>
        private Mock<IDatabase> _mockRepository;

        /// <summary>
        /// Mock repository for testing translation
        /// </summary>
        private Mock<IDatabase> _mockRepository2;

        /// <summary>
        /// Tages the data manager test_ setup.
        /// </summary>
        [TestInitialize]
        public void TagDataManagerTestSetup()
        {
            //var mockObjectSet = new MockObjectSet<Entities.Tag>();
            //mockObjectSet.AddObject(new Entities.Tag
            //{
            //    TagId = 1,
            //    Name = "Test1",
            //    TagTranslations =
            //        new EntityCollection<Entities.TagTranslation>
            //                                        {
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 1,
            //                                                    LanguageId = (int)LanguageType.Arabic,
            //                                                    Name = "تیست 1"
            //                                                },
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 1,
            //                                                    LanguageId = (int)LanguageType.Urdu,
            //                                                    Name = "ٹیسٹ 1"
            //                                                }
            //                                        }
            //});
            //mockObjectSet.AddObject(new Entities.Tag
            //{
            //    TagId = 2,
            //    Name = "Test2",
            //    TagTranslations =
            //        new EntityCollection<Entities.TagTranslation>
            //                                        {
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 2,
            //                                                    LanguageId = (int)LanguageType.Arabic,
            //                                                    Name = "تیست 2"
            //                                                },
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 2,
            //                                                    LanguageId = (int)LanguageType.Urdu,
            //                                                    Name = "ٹیسٹ 2"
            //                                                }
            //                                        }
            //});
            //mockObjectSet.AddObject(new Entities.Tag
            //{
            //    TagId = 3,
            //    Name = "Test3",
            //    TagTranslations =
            //        new EntityCollection<Entities.TagTranslation>
            //                                        {
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 3,
            //                                                    LanguageId = (int)LanguageType.Arabic,
            //                                                    Name = "تیست 3"
            //                                                },
            //                                            new Entities.TagTranslation
            //                                                {
            //                                                    TagId = 3,
            //                                                    LanguageId = (int)LanguageType.Urdu,
            //                                                    Name = "ٹیسٹ 3"
            //                                                }
            //                                        }
            //});
            //_mockRepository = new Mock<IDatabase>();
            //_mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);

            //var mockObjectSet2 = new MockObjectSet<Entities.TagTranslation>();
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Arabic,
            //    Name = "تیست 1",
            //    Tag = new Entities.Tag { TagId = 1 }
            //});
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Urdu,
            //    Name = "ٹیسٹ 1",
            //    Tag = new Entities.Tag { TagId = 1 }
            //});
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Arabic,
            //    Name = "تیست 2",
            //    Tag = new Entities.Tag { TagId = 2 }
            //});
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Urdu,
            //    Name = "ٹیسٹ 2",
            //    Tag = new Entities.Tag { TagId = 2 }
            //});
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Arabic,
            //    Name = "تیست 3",
            //    Tag = new Entities.Tag { TagId = 3 }
            //});
            //mockObjectSet2.AddObject(new Entities.TagTranslation
            //{
            //    LanguageId = (int)LanguageType.Urdu,
            //    Name = "ٹیسٹ 3",
            //    Tag = new Entities.Tag { TagId = 3 }
            //});

            //_mockRepository2 = new Mock<IDatabase>();
            //_mockRepository2.SetupGet(m => m.TagTranslation).Returns(mockObjectSet2);
        }

        #region Constructor Tests

        /// <summary>
        /// Tags the data manager default cosntruction test.
        /// </summary>
        /// <remarks></remarks>
        [TestMethod]
        public void TagDataManagerDefaultCosntructionTest()
        {
            var mockRepository = new Mock<IDatabase>();
            ServiceLocator.SetInjection(mockRepository.Object);
            new TagRepository();
            ServiceLocator.RemoveInjection<IDatabase>();
        }

        /// <summary>
        /// Tags the data manager cosntruction test with null repository.
        /// </summary>
        /// <remarks></remarks>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TagDataManagerCosntructionTestWithNullRepository()
        {
            IDatabase rep = null;
            new TagRepository(rep);
        }

        /// <summary>
        /// Tags the data manager cosntruction test with repository.
        /// </summary>
        /// <remarks></remarks>
        [TestMethod]
        public void TagDataManagerCosntructionTestWithRepository()
        {
            var rep = new Mock<IDatabase>();
            new TagRepository(rep.Object);
        }

        #endregion Constructor Tests

        #region GetTagList Tests

        /// <summary>
        /// Gets the tag list should not throw with empty repository.
        /// </summary>
        [TestMethod]
        public void GetTagListShouldNotThrowWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tags).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.Query(null, null, null);
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Gets the tag list should return returns records based on parameters.
        /// </summary>
        [TestMethod]
        public void GetTagListShouldReturnReturnsRecordsBasedOnParameters()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            for (int i = 0; i < 100; i++)
            {
                mockObjectSet.AddObject(new Entities.Tag
                {
                    TagId = i,
                    Name = "Tag " + i,
                    Meccan = i % 2 == 0,
                    Order = i
                });
            }
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagList(new Entity.Tag { NazoolType = NazoolType.Madani }, SortType.None, 3, 10);
            Assert.IsNotNull(result);
            AssertExtension.IsCollectionNotEmpty(result, 10);
            Assert.AreEqual(NazoolType.Madani, result.ElementAt(4).NazoolType);
            mockRepository.VerifyAll();
        }

        #endregion GetTagList Tests

        #region GetTagMatchingName Tests

        /// <summary>
        /// Gets the tag list should not throw with empty repository.
        /// </summary>
        [TestMethod]
        public void GetTagMatchingNameShouldNotThrowWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagMatchingName("something", LanguageType.Arabic, SortType.None, null, null);
            Assert.IsNotNull(result);
            AssertExtension.IsCollectionEmpty(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Gets the tag list should return returns records based on parameters.
        /// </summary>
        [TestMethod]
        public void GetTagMatchingNameShouldReturnReturnsRecordsBasedOnParameters()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            for (int i = 0; i < 100; i++)
            {
                mockObjectSet.AddObject(
                    new Entities.TagTranslation
                    {
                        TagId = i,
                        Name = "ٹیسٹ " + i,
                        LanguageId = (int)LanguageType.Arabic,
                        Tag = new Entities.Tag
                        {
                            Name = "Tag " + i,
                            Meccan = i % 2 == 0,
                            Order = i
                        }
                    });
            }

            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagMatchingName("یسٹ " + 1, LanguageType.Arabic, SortType.None, null, null);
            Assert.IsNotNull(result);
            AssertExtension.IsCollectionNotEmpty(result, 11);
            mockRepository.VerifyAll();
        }

        #endregion GetTagMatchingName Tests

        #region GetTagTranslatedName Tests

        /// <summary>
        /// Gets the tag translated name should return null with empty repository.
        /// </summary>
        [TestMethod]
        public void GetTagTranslatedNameShouldReturnNullWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagTranslatedName(7, LanguageType.Arabic);
            Assert.AreEqual(String.Empty, result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Gets the tag translated name should return null if no matching id found.
        /// </summary>
        [TestMethod]
        public void GetTagTranslatedNameShouldReturnNullIfNoMatchingIdFound()
        {
            var dao = new TagRepository(_mockRepository.Object);
            var result = dao.GetTagTranslatedName(5, LanguageType.Arabic);
            Assert.AreEqual(string.Empty, result);
            _mockRepository.VerifyAll();
        }

        /// <summary>
        /// Gets the tag translated name should return correct name if matching id found.
        /// </summary>
        [TestMethod]
        public void GetTagTranslatedNameShouldReturnCorrectNameIfMatchingIdFound()
        {
            var dao = new TagRepository(_mockRepository.Object);
            var result = dao.GetTagTranslatedName(2, LanguageType.Arabic);
            Assert.IsNotNull(result);
            Assert.AreEqual("تیست 2", result);
            _mockRepository.VerifyAll();
        }

        #endregion GetTagTranslatedName Tests

        #region GetByTranslatedName Tests

        /// <summary>
        /// Tages the data manager get tag by translated name test with empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByTranslatedNameTestWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagByTranslatedName("something", LanguageType.Arabic);
            Assert.IsNull(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by translated name test with matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByTranslatedNameTestWithMatchingRecords()
        {
            var dao = new TagRepository(_mockRepository2.Object);
            var result = dao.GetTagByTranslatedName("تیست 3", LanguageType.Arabic);
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Id);
            _mockRepository2.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by translated name test with no matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByTranslatedNameTestWithNoMatchingRecords()
        {
            var dao = new TagRepository(_mockRepository2.Object);
            var result = dao.GetTagByTranslatedName("Test 4", LanguageType.Arabic);
            Assert.IsNull(result);
            _mockRepository2.VerifyAll();
        }

        #endregion GetByTranslatedName Tests

        #region GetbyId Tests

        /// <summary>
        /// Tages the data manager get tag by id test with empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByIdTestWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagById(7, TextType.Default);
            Assert.IsNull(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by id test with matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByIdTestWithMatchingRecords()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test1" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 2, Name = "Test2" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 3, Name = "Test3" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagById(2, TextType.Default);
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Id);
            Assert.AreEqual("Test2", result.Name);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by id test with no matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByIdTestWithNoMatchingRecords()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test1" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 2, Name = "Test2" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 3, Name = "Test3" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagById(20, TextType.Default);
            Assert.IsNull(result);
            mockRepository.VerifyAll();
        }

        #endregion GetbyId Tests

        #region GetbyName Tests

        /// <summary>
        /// Tages the data manager get tag by name test with empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByNameTestWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagByName("something");
            Assert.IsNull(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by name test with matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByNameTestWithMatchingRecords()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test1" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 2, Name = "Test2" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 3, Name = "Test3" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagByName("Test1");
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("Test1", result.Name);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager get tag by name test with no matching records.
        /// </summary>
        [TestMethod]
        public void TagDataManagerGetTagByNameTestWithNoMatchingRecords()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test1" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 2, Name = "Test2" });
            mockObjectSet.AddObject(new Entities.Tag { TagId = 3, Name = "Test3" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.GetTagByName("Test 4");
            Assert.IsNull(result);
            mockRepository.VerifyAll();
        }

        #endregion GetbyName Tests

        #region InsertTag Tests

        /// <summary>
        /// Tages the data manager insert tag test with null argument.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TagDataManagerInsertTagTestWithNullArgument()
        {
            var mockRepository = new Mock<IDatabase>();
            var dao = new TagRepository(mockRepository.Object);
            dao.InsertTag(null);
        }

        /// <summary>
        /// Tages the data manager insert tag test with empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerInsertTagTestWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges());
            mockRepository.Setup(m => m.Refresh(RefreshMode.StoreWins, It.IsAny<Entities.Tag>()));
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.InsertTag(new Entity.Tag { Id = 1, Name = "Test" });
            Assert.AreEqual(1, mockObjectSet.Count());
            Assert.IsNotNull(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager insert tag test with non empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerInsertTagTestWithNonEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges());
            mockRepository.Setup(m => m.Refresh(RefreshMode.StoreWins, It.IsAny<Entities.Tag>()));
            var dao = new TagRepository(mockRepository.Object);

            Assert.AreEqual(1, mockObjectSet.Count());

            var result = dao.InsertTag(new Entity.Tag { Id = 2, Name = "Test2" });

            Assert.AreEqual(2, mockObjectSet.Count());
            Assert.IsNotNull(result);
            mockRepository.VerifyAll();
        }

        #endregion InsertTag Tests

        #region Udpate Tests

        /// <summary>
        /// Tages the data manager update tag test with null argument.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TagDataManagerUpdateTagTestWithNullArgument()
        {
            var mockRepository = new Mock<IDatabase>();
            var dao = new TagRepository(mockRepository.Object);
            dao.UpdateTag(null);
        }

        /// <summary>
        /// Tages the data manager update tag test with no matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerUpdateTagTestWithNoMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var id = dao.UpdateTag(new Entity.Tag { Id = 2, Name = "Updated Test" });

            Assert.AreEqual(-1, id);
            Assert.AreEqual(1, mockObjectSet.Count());
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager update tag test with matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerUpdateTagTestWithMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges()).Returns(1);

            var dao = new TagRepository(mockRepository.Object);
            var id = dao.UpdateTag(new Entity.Tag { Id = 1, Name = "Updated Test" });

            Assert.AreEqual(1, id);
            Assert.AreEqual(1, mockObjectSet.Count());
            mockRepository.VerifyAll();
        }

        #endregion Udpate Tests

        #region Delete Tests

        /// <summary>
        /// Tages the data manager delete tag test with no matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerDeleteTagTestWithNoMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            dao.DeleteTag(2);

            Assert.AreEqual(1, mockObjectSet.Count());
        }

        /// <summary>
        /// Tages the data manager delete tag test with matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerDeleteTagTestWithMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.Tag>();
            mockObjectSet.AddObject(new Entities.Tag { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.Tag).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            dao.DeleteTag(1);

            Assert.AreEqual(0, mockObjectSet.Count());
        }

        #endregion Delete Tests

        #region InsertTagTranslation Tests

        /// <summary>
        /// Tages the data manager insert tag translation test with null argument.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TagDataManagerInsertTagTranslationTestWithNullArgument()
        {
            var mockRepository = new Mock<IDatabase>();
            var dao = new TagRepository(mockRepository.Object);
            dao.InsertTagTranslation(null);
        }

        /// <summary>
        /// Tages the data manager insert tag translation test with empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerInsertTagTranslationTestWithEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges());
            mockRepository.Setup(m => m.Refresh(RefreshMode.StoreWins, It.IsAny<Entities.TagTranslation>()));
            var dao = new TagRepository(mockRepository.Object);
            var result = dao.InsertTagTranslation(new Entity.TagTranslation { Id = 1, Name = "Test" });
            Assert.AreEqual(1, mockObjectSet.Count());
            Assert.IsNotNull(result);
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager insert tag translation test with non empty repository.
        /// </summary>
        [TestMethod]
        public void TagDataManagerInsertTagTranslationTestWithNonEmptyRepository()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            mockObjectSet.AddObject(new Entities.TagTranslation { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges());
            mockRepository.Setup(m => m.Refresh(RefreshMode.StoreWins, It.IsAny<Entities.TagTranslation>()));
            var dao = new TagRepository(mockRepository.Object);

            Assert.AreEqual(1, mockObjectSet.Count());

            var result = dao.InsertTagTranslation(new Entity.TagTranslation { Id = 2, Name = "Test2" });

            Assert.AreEqual(2, mockObjectSet.Count());
            Assert.IsNotNull(result);
            mockRepository.VerifyAll();
        }

        #endregion InsertTagTranslation Tests

        #region UpdateTagTranslation Tests

        /// <summary>
        /// Tages the data manager update tag translation test with null argument.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TagDataManagerUpdateTagTranslationTestWithNullArgument()
        {
            var mockRepository = new Mock<IDatabase>();
            var dao = new TagRepository(mockRepository.Object);
            dao.UpdateTagTranslation(null);
        }

        /// <summary>
        /// Tages the data manager update tag translation test with no matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerUpdateTagTranslationTestWithNoMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            mockObjectSet.AddObject(new Entities.TagTranslation { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            var id = dao.UpdateTagTranslation(new Entity.TagTranslation { Id = 2, Name = "Updated Test" });

            Assert.AreEqual(-1, id);
            Assert.AreEqual(1, mockObjectSet.Count());
            mockRepository.VerifyAll();
        }

        /// <summary>
        /// Tages the data manager update tag translation test with matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerUpdateTagTranslationTestWithMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            mockObjectSet.AddObject(new Entities.TagTranslation { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            mockRepository.Setup(m => m.SaveChanges()).Returns(1);

            var dao = new TagRepository(mockRepository.Object);
            var id = dao.UpdateTagTranslation(new Entity.TagTranslation { Id = 1, Name = "Updated Test" });

            Assert.AreEqual(1, id);
            Assert.AreEqual(1, mockObjectSet.Count());
            mockRepository.VerifyAll();
        }

        #endregion UpdateTagTranslation Tests

        #region DeleteTagTranslation Tests

        /// <summary>
        /// Tages the data manager delete tag translation test with no matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerDeleteTagTranslationTestWithNoMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            mockObjectSet.AddObject(new Entities.TagTranslation { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            dao.DeleteTagTranslation(2);

            Assert.AreEqual(1, mockObjectSet.Count());
        }

        /// <summary>
        /// Tages the data manager delete tag translation test with matching record.
        /// </summary>
        [TestMethod]
        public void TagDataManagerDeleteTagTranslationTestWithMatchingRecord()
        {
            var mockObjectSet = new MockObjectSet<Entities.TagTranslation>();
            mockObjectSet.AddObject(new Entities.TagTranslation { TagId = 1, Name = "Test" });
            var mockRepository = new Mock<IDatabase>();
            mockRepository.SetupGet(m => m.TagTranslation).Returns(mockObjectSet);
            var dao = new TagRepository(mockRepository.Object);
            dao.DeleteTagTranslation(1);

            Assert.AreEqual(0, mockObjectSet.Count());
        }

        #endregion DeleteTagTranslation Tests
    }
}